package com.opbx.callCenter.service.impl;

import java.beans.Transient;
import java.util.List;
import com.opbx.common.utils.DateUtils;
import com.opbx.freeswitch.extension.ExtensionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.opbx.callCenter.mapper.CallCenterExtensionMapper;
import com.opbx.callCenter.domain.CallCenterExtension;
import com.opbx.callCenter.service.ICallCenterExtensionService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 分机设置Service业务层处理
 * 
 * @author opbx
 * @date 2024-06-05
 */
@Service
public class CallCenterExtensionServiceImpl implements ICallCenterExtensionService 
{
    @Autowired
    private CallCenterExtensionMapper callCenterExtensionMapper;
    @Autowired
    private ExtensionService extensionService;
    /**
     * 查询分机设置
     * 
     * @param id 分机设置主键
     * @return 分机设置
     */
    @Override
    public CallCenterExtension selectCallCenterExtensionById(Long id)
    {
        return callCenterExtensionMapper.selectCallCenterExtensionById(id);
    }

    /**
     * 查询分机设置列表
     * 
     * @param callCenterExtension 分机设置
     * @return 分机设置
     */
    @Override
    public List<CallCenterExtension> selectCallCenterExtensionList(CallCenterExtension callCenterExtension)
    {
        return callCenterExtensionMapper.selectCallCenterExtensionList(callCenterExtension);
    }

    /**
     * 新增分机设置
     * 
     * @param callCenterExtension 分机设置
     * @return 结果
     */
    @Transactional
    @Override
    public int insertCallCenterExtension(CallCenterExtension callCenterExtension)
    {
        String userid = callCenterExtension.getUserid();
        String password = callCenterExtension.getPassword();
        callCenterExtension.setCreateTime(DateUtils.getNowDate());
        int i = callCenterExtensionMapper.insertCallCenterExtension(callCenterExtension);
        //新增xml
        int status = extensionService.addUserXml(userid, password);
        //重载配置文件


        return status;
    }

    /**
     * 修改分机设置
     * 
     * @param callCenterExtension 分机设置
     * @return 结果
     */
    @Override
    public int updateCallCenterExtension(CallCenterExtension callCenterExtension)
    {
        callCenterExtension.setUpdateTime(DateUtils.getNowDate());
        return callCenterExtensionMapper.updateCallCenterExtension(callCenterExtension);
    }

    /**
     * 批量删除分机设置
     * 
     * @param ids 需要删除的分机设置主键
     * @return 结果
     */
    @Override
    public int deleteCallCenterExtensionByIds(Long[] ids)
    {
        return callCenterExtensionMapper.deleteCallCenterExtensionByIds(ids);
    }

    /**
     * 删除分机设置信息
     * 
     * @param id 分机设置主键
     * @return 结果
     */
    @Override
    public int deleteCallCenterExtensionById(Long id)
    {
        return callCenterExtensionMapper.deleteCallCenterExtensionById(id);
    }

    /**
     * 改变分机状态
     * @param callCenterExtension
     * @return
     */
    @Override
    public int changeExtensionStatus(CallCenterExtension callCenterExtension) {
        int i = callCenterExtensionMapper.updateCallCenterExtension(callCenterExtension);
        return i;
    }
}
